﻿namespace ODataValidator.Rule.Helper
{
    #region Namesapces
    using System.CodeDom;
    using System.IO;
    using Microsoft.CSharp;
    #endregion

    /// <summary>
    /// String Helper class
    /// </summary>
    public static class StringHelper
    {
        /// <summary>
        /// Generates full literal representation of a string 
        /// </summary>
        /// <param name="input">The string input, like "hello,\t\".NET\""</param>
        /// <returns>The full literal of the string, like "\"hello,\\t\\\".NET\\\"\""</returns>
        public static string ToLiteral(string input)
        {
            var writer = new StringWriter();
            var codeGen = new CSharpCodeProvider();
            codeGen.GenerateCodeFromExpression(new CodePrimitiveExpression(input), writer, null);
            return writer.ToString();
        }
    }
}
